<?php


namespace App\Utils\Notice;


use App\Model\NoticeUser;
use Hyperf\DbConnection\Model\Model;

/**
 * 审核人员通过了企业实名人工审核
 * 发送方：母公司
 * 接收方：用户
 * Class UserCertificationCompanyAuditAllow
 * @package App\Utils\Notice
 */
class UserCertificationCompanyAuditNotAllow extends Notice
{

    public $messageTemplate = '您好，很抱歉您的企业实名审核未通过，原因如下：“%message%”，请修改后重新提交';

    //前端路由-企业实名页面
    public $routeName = '/pages/certification/approve?type=2';

    function toDatabase()
    {
        $data = $this->format($this->data);
        /** @var Model $model */
        $model = new NoticeUser();
        $model->fill($data)->save();
    }

    public function format($data)
    {
        $return =  [
            'user_id' => $this->receiverId,
            'content' => $this->messageTemplate,
            'type' => \App\Constants\Model\Notice::USER_CERTIFICATION_COMPANY_AUDIT_NOT_ALLOW,
            'extension' => [
                'path' => $this->routeName
            ]
        ];

        $searches = [];
        foreach ($data['replaces'] as $replace => $content) {
            $searches[] = '%' . $replace . '%';
        }
        $return['content'] = str_replace($searches, $data['replaces'], $this->messageTemplate);

        return $return;

    }
}